<?php
namespace app\customer\model;

use app\BaseModel;

class StaffHand extends BaseModel
{
    //员工交接记录表
    protected $name = 'longbing_card_staff_hand_log';

    protected $append = [

        'action_text'
    ];

    /**
     * @param $value
     * @param $data
     * @功能说明:时间转换
     * @author chenniang
     * @DataTime: 2020-01-10 15:12
     */
    public function getCreatetimeAttr($value,$data){
        return date('Y-m-d H:i:s',$value);
    }


    /**
     * @param $value
     * @param $data
     * @功能说明:
     * @author chenniang
     * @DataTime: 2020-01-10 15:14
     */
    public function getActionTextAttr($value,$data){
        if(!empty($data['action'])){
            return $data['action'] ==1?'创建名片':'取消名片';
        }
    }


    /**
     * @param $data
     * @功能说明: 添加记录
     * @author chenniang
     * @DataTime: 2020-01-10 14:14
     */
    public function addLog($data){
        $data['create_time'] = time();
        $data['status']      = 1;
        $res = $this->insert($data);
        return $res;
    }


    /**
     * @param $dis
     * @param int $page
     * @功能说明:员工交接日志
     * @author chenniang
     * @DataTime: 2020-01-10 14:56
     */
    public function handLogList($dis,$page=10){

        $data = $this->alias('a')
                ->join('longbing_card_user_info b','a.staff_id = b.fans_id','left')
                ->join('longbing_card_user_info b','a.to_staff_id = b.fans_id','left')
                ->where($dis)
                ->field('a.timeline,a.card_qr,a.create_time,b.name as staff_name,c.name as to_staff_name')
                ->group('a.id')
                ->paginate($page)
                ->toArray();
        return $data;
    }

    /**
     * @param $dis
     * @功能说明:获取被交接员工的id
     * @author chenniang
     * @DataTime: 2020-01-10 15:38
     */
    public function getToStaffId($dis){
        $id = $this->where($dis)->order('id desc')->value('to_staff_id');
        return $id;
    }




    public function getToStaff($dis){
        $id = $this->where($dis)->order('id desc')->find();
        return !empty($id)?$id->toArray():[];
    }

}